package isp.apps.example.shoppingcart.action;

import isp.apps.example.shoppingcart.domain.Item;
import isp.apps.example.shoppingcart.persistence.ItemDirectory;
import isp.apps.example.shoppingcart.persistence.factory.ItemPersistenceFactory;
import isp.apps.example.shoppingcart.domain.ShoppingCart;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class DeleteItemAction
  extends ShoppingAction
{
  private Map itemsMap;

  private String deleteSku;

  private Item removeItem;


  public DeleteItemAction()
  {
  }

  public Map getItemsMap()
  {
    if (itemsMap == null)
      itemsMap = new HashMap();
    return itemsMap;
  }

  public void setSku(String newSku)
  {
    deleteSku = newSku;
  }

  public String execute()
  {
    ShoppingCart myShoppingCart = getCart();
    myShoppingCart.removeBySku(deleteSku);
    return SUCCESS;
  }

  public void validate()
  {

    if (deleteSku == null)
      addActionError("Sku is null");
  }
}
